/*
 *   Copyright (C) 2010  Jens Kieselbach
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 * 
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */

package de.kieselbach.grootional.component

import com.jgoodies.forms.builder.*
import com.jgoodies.forms.layout.*
import de.kieselbach.io.*
import de.kieselbach.grootional.util.*
import de.kieselbach.grootional.value.*
import de.kieselbach.sql.*
import de.kieselbach.swing.*
import de.kieselbach.swing.border.*
import de.kieselbach.swing.table.*
import de.kieselbach.swing.text.*
import de.kieselbach.swing.validation.*
import java.sql.*
import java.util.logging.*
import java.text.*
import javax.swing.*
import javax.swing.event.*
import javax.swing.text.*
import javax.swing.tree.*

import java.awt.event.*
import java.awt.BorderLayout
import java.awt.Color
import java.awt.Dimension
import java.awt.Font
import java.awt.Graphics
import java.awt.Point

class OutputCard extends Card {

    def dabaseFrame
    def frame
    def uiResources
    def resourceBundle

    def textArea
	def document

    OutputCard(def dbframe) {
        
        super(new BorderLayout())
        addToolBarGlue = true

        dabaseFrame = dbframe
        frame = dbframe.frame
        uiResources = dbframe.uiResources
        resourceBundle = uiResources.resourceBundles['gui']

        title = resourceBundle.getString('sqlOutput.title')
        icon = uiResources.images['terminal16'] as Icon

		def clearButton = new FlatButton(uiResources.images['clear16'])
		clearButton.enabled = true
		clearButton.toolTipText = resourceBundle.getString('sqlOutput.clear')
		toolBarItems << clearButton
		clearButton.actionPerformed = {
			textArea.text = ''
		}
		
        textArea = new JTextPane()
		document = new DefaultStyledDocument()
		textArea.document = document
		
        def scroll = new JScrollPane(textArea)

        textArea.setFont(new Font("Monospaced", Font.PLAIN, 12))
		textArea.editable = false
		
        add(scroll, BorderLayout.CENTER)
		
		
    }
	
	void append(String sql) {

//		SimpleAttributeSet attr = new SimpleAttributeSet();
//		StyleConstants.setBold(attr , true);
//		StyleConstants.setForeground(attr, Color.RED);
		
		
		document.insertString(document.length, sql, null)
	}
}

